﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="imap.aspx.cs" Inherits="weba.imap" %>

<%@ Register Assembly="C1.Web.Wijmo.Controls.4, Version=4.0.20133.145, Culture=neutral, PublicKeyToken=9b75583953471eea" Namespace="C1.Web.Wijmo.Controls.C1ProgressBar" TagPrefix="wijmo" %>

<%@ Register Assembly="C1.Web.Wijmo.Controls.4, Version=4.0.20133.145, Culture=neutral, PublicKeyToken=9b75583953471eea" Namespace="C1.Web.Wijmo.Controls.C1Menu" TagPrefix="wijmo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style type="text/css">  
html{height:100%}  
body{height:100%;margin:0px;padding:0px}  
#container{ height: 500px;width: 700px}  
        #playctrl {
            visibility: visible;
        }
        #sudu {
            width: 37px;
        }
    </style>  
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=mxVHWuGjH42qy24GZG40ieC1"></script>
</head>
<body onload="xaainit()">
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
            <Services>
                <asp:ServiceReference Path="wajax.asmx"  />
            </Services>
        </asp:ScriptManager>
    <div>
   
       <%-- <br/>
        <input id="Button1" type="button" value="添加" onclick="JavaScript :xaa()" />
        <input id="Button2" type="button" value="清除" onclick="JavaScript: xcc()"/>
         <input id="Button3" type="button" value="所有网点" onclick="JavaScript: xal()"/>--%>
        <br/>
        <wijmo:C1Menu ID="C1Menu1" runat="server" BackLinkText="后退" CrumbDefaultText="选择一个选项" TopLinkText="全部" ShowDelay="50" >
<Animation Option=""></Animation>

<ShowAnimation Option=""></ShowAnimation>

          <HideAnimation Option="">
<Animated Effect="fade"></Animated>
</HideAnimation>
            <Items>
                <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:xaa()" Text="显示总览">
                </wijmo:C1MenuItem>
                <wijmo:C1MenuItem runat="server" Text="邮政网点">
                    <Items>
                        <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:xal()" Text="添加所有">
                        </wijmo:C1MenuItem>
                        <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:byqa()"  Text="添加当前区域">
                        </wijmo:C1MenuItem>
                        <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:rma()" Text="清除所有">
                        </wijmo:C1MenuItem>
                    </Items>
                </wijmo:C1MenuItem>
                <wijmo:C1MenuItem runat="server" Text="快递网点">
                    <Items>
                        <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:xam()" Text="添加所有">
                        </wijmo:C1MenuItem>
                        <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:byqb()" Text="添加当前区域">
                        </wijmo:C1MenuItem>
                        <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:rmb()"  Text="清除所有">
                        </wijmo:C1MenuItem>
                    </Items>
                </wijmo:C1MenuItem>
                <wijmo:C1MenuItem runat="server" Text="轨迹回放">
                    <Items>
                        <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:addtstart()" Text="添加起点">
                        </wijmo:C1MenuItem>
                        <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:addend()" Text="添加终点">
                        </wijmo:C1MenuItem>
                        <wijmo:C1MenuItem runat="server" NavigateUrl="JavaScript:calway()" Text="计算路径">
                        </wijmo:C1MenuItem>
                    </Items>
                </wijmo:C1MenuItem>
                <wijmo:C1MenuItem runat="server"  NavigateUrl="JavaScript:xcc()" Text="全部清空">
                </wijmo:C1MenuItem>
            </Items>
        </wijmo:C1Menu>
       
        <br/>
         <div id="container"></div> 
         <br/> 
        <div id="playctrl">
            <wijmo:C1ProgressBar ID="C1ProgressBar1" runat="server"></wijmo:C1ProgressBar>
            <input id="follow" type="checkbox"/><span style="font-size:12px;">画面跟随</span>
            <input id="plays" type="button" value="播放" onclick="play()"/>
		<input id="pauses" type="button" value="暂停" onclick="pause()"/>
          
		<input id="reset"  type="button" value="重置" onclick="rss()"/> 
             <span style="font-size:12px;">播放速度</span>
<input id="sudu" type="text"  onblur="chgsudu()" value="200" />         <span style="font-size:12px;">:越小越快</span>&nbsp;
        </div>
    </div>
    </form>
</body>
</html>
<script type="text/javascript">
    var ar = [0, 0];
    var quyu;
    var pts, pte;
    var markers, markere;
    var amk = new Array();
    var followChk;
    var timer;
    var index = 0;
    var spsudu=200;
    var map = new BMap.Map("container"); 
    var points// 创建地图实例  
    var point = new BMap.Point(121.569041, 29.867279);  // 创建点坐标  
    map.centerAndZoom(point, 10);
    map.addControl(new BMap.NavigationControl());
    map.enableScrollWheelZoom();// 初始化地图，设置中心点坐标和地图级别 
    var driving = new BMap.DrivingRoute(map, { renderOptions: { map: map, autoViewport: true } });
    /* map.addEventListener("click", function (e) {
        alert(e.point.lng + ", " + e.point.lat);
    });*/
    /* var bdary = new BMap.Boundary();
    bdary.get("海曙区", function (rs) {       //获取行政区域
        //这里是用户自己的函数。 
        var count = rs.boundaries.length; //行政区域的点有多少个
        for (var i = 0; i < count; i++) {
            var ply = new BMap.Polygon(rs.boundaries[i], { strokeWeight: 2, strokeColor: "#ff0000" }); //建立多边形覆盖物
            map.addOverlay(ply);  //添加覆盖物
        }
    });*/
/*    bdary.get("江北区", function (rs) {       //获取行政区域
        //这里是用户自己的函数。 
        var count = rs.boundaries.length; //行政区域的点有多少个
        for (var i = 0; i < count; i++) {
            var ply = new BMap.Polygon(rs.boundaries[i], { strokeWeight: 2, strokeColor: "#00FF00" }); //建立多边形覆盖物
            map.addOverlay(ply);  //添加覆盖物
        }
    });
    */
    function dgf() {
        $("#plays").prop("disabled", "disabled");
    }
    function chgsudu() {
    spsudu=   event.srcElement.value;
    }
    function rss() {
        $("#pauses").prop("disabled", "disabled");
        $("#plays").prop("disabled", "");
        if (timer) {
            window.clearTimeout(timer);
        }
        index = 0;
        car.setPosition(points[0]);
        map.panTo(centerPoint);        $("#C1ProgressBar1").c1progressbar("option", "value", 0);
    }
    function play() {
        $("#pauses").prop("disabled", "");
        $("#plays").prop("disabled", "disabled");
        var point = points[index];
        if (index > 0) {
            map.addOverlay(new BMap.Polyline([points[index - 1], point], { strokeColor: "red", strokeWeight: 1, strokeOpacity: 1 }));
        }
        label.setContent("经度: " + point.lng + "<br>纬度: " + point.lat);
        $("#C1ProgressBar1").c1progressbar("option", "value", 100 * (index / points.length));
       
        car.setPosition(point);
        index++;
        if (followChk.checked) {
            map.panTo(point);
        }
        if (index < points.length) {
            timer = window.setTimeout("play(" + index + ")", spsudu);
        } else {
            
            map.panTo(point);
            $("#C1ProgressBar1").c1progressbar("option", "value", 0);
        }
    }

    function pause() {
        //   alert($("#sudu").prop("value"));
        $("#pauses").prop("disabled", "disabled");
        $("#plays").prop("disabled", "");
        if (timer) {
            window.clearTimeout(timer);
        }
      //  $("#C1ProgressBar1").c1progressbar("option", "value", 80);
    }

    function calway() {
        driving.search(pts, pte);
        driving.setSearchCompleteCallback(function () {
            //得到路线上的所有point
            map.removeOverlay(markers);
            map.removeOverlay(markere);
            points = driving.getResults().getPlan(0).getRoute(0).getPath();
            //画面移动到起点和终点的中间
            centerPoint = new BMap.Point((points[0].lng + points[points.length - 1].lng) / 2, (points[0].lat + points[points.length - 1].lat) / 2);
            map.panTo(centerPoint);
            //连接所有点
            map.addOverlay(new BMap.Polyline(points, { strokeColor: "black", strokeWeight: 5, strokeOpacity: 1 }));

            //显示小车子
            label = new BMap.Label("", { offset: new BMap.Size(-20, -20) });
            car = new BMap.Marker(points[0], { icon: new BMap.Icon("Images/car.png", new BMap.Size(48, 48), { imageOffset: new BMap.Size(0, 0) }) });
            car.setLabel(label);
            map.addOverlay(car);

            //点亮操作按钮

        });
        $("#playctrl").show();
    }
    
    function addtstart() {
         pts = new BMap.Point(map.getCenter().lng, map.getCenter().lat);
        var myIcon = new BMap.Icon("Images/tostart.png", new BMap.Size(41, 40))
         markers = new BMap.Marker(pts, { icon: myIcon });        // 创建标注    
         map.addOverlay(markers);
         markers.enableDragging();
         markers.addEventListener("dragend", function (e) {
             //   alert("当前位置：" +  + ", " + 
             pts = new BMap.Point(e.point.lng,e.point.lat);
         })
    }

    function addend() {
         pte = new BMap.Point(map.getCenter().lng, map.getCenter().lat);
        var myIcon = new BMap.Icon("Images/toend.png", new BMap.Size(41, 46))
         markere = new BMap.Marker(pte, { icon: myIcon });        // 创建标注    
         map.addOverlay(markere);
         markere.enableDragging();
         markere.addEventListener("dragend", function (e) {
           //  alert("当前位置：" + e.point.lng + ", " + e.point.lat);
             pte = new BMap.Point(e.point.lng, e.point.lat);
         })
    }
    function byqa() {
        ar[0] = 1;
        ar[1] = 0;
        weba.wajax.getbyquyu(quyu, ar, rtid);
    }
    function byqb() {
        ar[0] = 0;
        ar[1] = 1;
        weba.wajax.getbyquyu(quyu, ar, rtid);
    }
    function suc(result) {
        //   alert(result.length); 
       
           
        for (var i = 0; i < result.length; i++) {
            xh(result[i].lx, result[i].ly, result[i].Id, result[i].name, result[i].shuoming, result[i].tupianurl, result[i].pid);
        }
    }
    function suca(result) {
        //   alert(result.length); 
        var pointa = new BMap.Point(result[0].lx, result[0].ly);  // 创建点坐标  
        map.centerAndZoom(pointa, 11);

        for (var i = 0; i < result.length; i++) {
            xh(result[i].lx, result[i].ly, result[i].Id, result[i].name, result[i].shuoming, result[i].tupianurl, result[i].pid);
        }
    }
    function rma() {
        ar[0] = 0;
        // alert(map.getOverlays().length);
        var ovm = map.getOverlays();
       // alert(ovm.length)
      // k = 0;
        for (var i = 0; i <ovm.length; i++) {

           // alert(ovm[i].prototype ==  BMap.Polygon());
             if (ovm[i].__proto__.Zu=="Marker")
            {
                //  k++;
                if (ovm[i].getIcon().imageUrl == "http://webapi.amap.com/images/marker_sprite.png") {
                    map.removeOverlay(ovm[i]);
                }
                
            }
        }
            
       
      //  alert(k);
    }
    function rmb() {
        ar[1] = 0;
        // alert(map.getOverlays().length);
        var ovm = map.getOverlays();
        // alert(ovm.length)
        // k = 0;
        for (var i = 0; i < ovm.length; i++) {

            // alert(ovm[i].prototype ==  BMap.Polygon());
            if (ovm[i].__proto__.Zu == "Marker") {
                //  k++;
                if (ovm[i].getIcon().imageUrl == "http://webapi.amap.com/images/0.png") {
                    map.removeOverlay(ovm[i]);
                }

            }
        }


        //  alert(k);
    }
    function sucm(result) {
        //   alert(result.length);
       
        for (var i = 0; i < result.length; i++) {
            xhm(result[i].lx, result[i].ly, result[i].Id, result[i].name, result[i].shuoming, result[i].tupianurl, result[i].pid);
        }
    }
    function sucma(result) {
        //   alert(result.length);
        var pointab = new BMap.Point(result[0].lx, result[0].ly);  // 创建点坐标  
        map.centerAndZoom(pointab, 11);
        for (var i = 0; i < result.length; i++) {
            xhm(result[i].lx, result[i].ly, result[i].Id, result[i].name, result[i].shuoming, result[i].tupianurl, result[i].pid);
        }
    }

    function xh(rx, ry, d, nm, sm, ig, pdi) {
        var point = new BMap.Point(rx, ry);
       var myIcon = new BMap.Icon("http://webapi.amap.com/images/marker_sprite.png", new BMap.Size(23, 25))
        var marker = new BMap.Marker(point,{icon: myIcon});        // 创建标注    
        map.addOverlay(marker);
    }
    function xhm(rx, ry, d, nm, sm, ig, pdi) {
        var point = new BMap.Point(rx, ry);
        var myIcon = new BMap.Icon("http://webapi.amap.com/images/0.png", new BMap.Size(23, 25))
        var marker = new BMap.Marker(point, {icon: myIcon});        // 创建标注    
        map.addOverlay(marker);
    }

    function xal() {
        weba.wajax.getbyid("1", suc);
        //  ar.push(3, 4, 5, 6, 7, 8, 9);
        ar[0] = 1;

    }
    function xam() {
        weba.wajax.getbyid("2", sucm);
        ar[1] = 1;
        // ar.push(10, 11, 12, 13, 14, 15, 16);
    }
    function rtid(result) {
       // alert(result.length);
        if (result.length == 2) {
            weba.wajax.getbyid(result[0], suca);
            weba.wajax.getbyid(result[1], sucma);
        }
        if (result.length == 1& ar[0]==1) {
            weba.wajax.getbyid(result[0], suca); 
        }
        if (result.length == 1& ar[1]==1) {
            weba.wajax.getbyid(result[0], sucma); 
        }
    }
    function getbyq(parameters,colr) {
        var bdary = new BMap.Boundary();
        bdary.get(parameters, function (rs) {       //获取行政区域
            //这里是用户自己的函数。 
            var count = rs.boundaries.length; //行政区域的点有多少个
            for (var i = 0; i < count; i++) {
                var ply = new BMap.Polygon(rs.boundaries[i], {
                    strokeWeight: 2, strokeColor: colr, fillColor: colr,fillOpacity: 0.1
                }); //建立多边形覆盖物
                map.addOverlay(ply);  //添加覆盖物
            }
            ply.addEventListener("click", function(e) {
                // alert(colr);
                quyu = parameters;
                map.clearOverlays();
                map.addOverlay(ply);
                // weba.wajax.getbyid(partid, suc);
                weba.wajax.getbyquyu(parameters, ar,rtid);
            })
            // weba.wajax.getbyid(partid, suc);
        });
    }

    function xcc() {
        map.clearOverlays();
        $("#playctrl").hide();
    }

    function xaainit() {
        followChk = document.getElementById("follow");
        $("#playctrl").hide();
        $("#pauses").prop("disabled", "disabled");
        var point = new BMap.Point(121.569041, 29.867279);  // 创建点坐标  
        map.centerAndZoom(point, 10);
        getbyq("宁波市江北区", "#00FF00");
        getbyq("宁波市海曙区", "#ff0000");
        getbyq("宁波市鄞州区", "#003DF5");
        getbyq("宁波市江东区", "#FF6633");
        getbyq("宁波市余姚市", "#CC33FF");
        getbyq("宁波市奉化市", "#33CCFF");
        getbyq("宁波市慈溪市", "#FF6633");
        getbyq("宁波市镇海区", "#33FF66");
        getbyq("宁波市北仑区", "#B88A00");
    }

    function xaa() {
       
        // bdary.get();
        if (map.getOverlays().length == 0) {
            var point = new BMap.Point(121.569041, 29.867279);  // 创建点坐标  
            map.centerAndZoom(point, 10);
            getbyq("宁波市江北区", "#00FF00");
            getbyq("宁波市海曙区", "#ff0000");
            getbyq("宁波市鄞州区", "#003DF5");
            getbyq("宁波市江东区", "#FF6633");
            getbyq("宁波市余姚市", "#CC33FF");
            getbyq("宁波市奉化市", "#33CCFF");
            getbyq("宁波市慈溪市", "#FF6633");
            getbyq("宁波市镇海区", "#33FF66");
            getbyq("宁波市北仑区", "#B88A00");
        }
    }
</script>  